package com.example.lenovo.appstore.activity;

import android.os.Bundle;
import android.webkit.WebView;

import com.example.lenovo.appstore.R;
import com.example.lenovo.appstore.view.TitleBarView;
import com.tamic.jswebview.browse.JsWeb.CustomWebViewClient;
import com.tamic.jswebview.view.ProgressBarWebView;

import java.util.Map;

import androidx.appcompat.app.AppCompatActivity;
import butterknife.Bind;
import butterknife.ButterKnife;

public class WebViewActivity extends AppCompatActivity {
    @Bind(R.id.index_titleBar)
    TitleBarView index_titleBar;
    @Bind(R.id.login_progress_webview)
    ProgressBarWebView mProgressBarWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view);
        ButterKnife.bind(this);
        mProgressBarWebView.setWebViewClient(new CustomWebViewClient(mProgressBarWebView.getWebView()) {
            @Override
            public String onPageError(String url) {
                //指定网络加载失败时的错误页面
                return "file:///android_asset/error.html";
            }

            @Override
            public Map<String, String> onPageHeaders(String url) {

                // 可以加入header

                return null;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                index_titleBar.setTitle(view.getTitle());
            }
        });

        // 打开页面，也可以支持网络url
        mProgressBarWebView.loadUrl(getIntent().getStringExtra("url"));
    }

}
